package net.wang.concurrency.test.immutable;

import net.wang.concurrency.annoations.ThreadSafe;

import java.util.Collections;
import java.util.Map;

/**
 * 不可变对象
 */
@ThreadSafe
public class ImmutableExample2 {

    private static Map<Integer, Integer> map;

    static {
        map.put(1, 2);
        map.put(3, 4);
        map.put(5, 6);
        //继承Map 将修改的方法都改写成抛出异常
        map = Collections.unmodifiableMap(map);
    }

    public static void main(String[] args) {

        map.put(1, 3);
        System.out.println(map.get(1));
    }

}
